package games.car;


import java.awt.*;

import static games.car.Images.*;

public class Prop {

    private int x, y;
    private int yspeed = games.car.Config.PROP_DEFAULT_SPEED;
    private boolean live = true;
    private Image image = null;
    private Type type;
    public enum Type{
        GOLD,COVER,FIRE,SPEED
    }

    public Prop(int x, int y,Type type){
        this.x = x;
        this.y = y;
        this.type = type;
        if(type == Type.COVER){
            image = COVER_IMG;
        }else if(type == Type.FIRE){
            image = FIRE_IMG;
        }else if(type == Type.GOLD){
            image = GOLD_IMG;
        }else if(type == Type.SPEED){
            image = SPEED_IMG;
        }
    }

    void draw(Graphics g) {
        g.drawImage(image, x, y,(int)(games.car.Config.CAR_WIDTH * 0.75),(int)(games.car.Config.CAR_HEIGHT * 0.75),null);

        move();
    }

    void move() {
        if (y < games.car.Config.WINDOW_HEIGHT - games.car.Config.FRAME_WIDTH - yspeed){
            y += yspeed;
        }else{
            this.live = false;
        }
    }

    boolean isLive(){
        return live;
    }

    Rectangle getRect() {
        return new Rectangle(x, y, (int)(games.car.Config.CAR_WIDTH * 0.5), (int)(games.car.Config.CAR_HEIGHT * 0.5));
    }

    boolean collision(games.car.Car car) {
        if (this.live && car.isLive() && car.isPlayer()) {
            if (this.getRect().intersects(car.getRect())) {
                this.live = false;
                if(games.car.Config.soundOn){
                    new games.car.Voice(games.car.Config.PROP_VOICE).start();
                }
                return true;
            }
        }
        return false;
    }

    public boolean typeEq(Type type){
        return this.type == type;
    }

    public Image getImg(){
        return image;
    }
}
